﻿<Window x:Class="ShareDeployed.Mailgrabber.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
		xmlns:cmd="clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.Extras.WPF4"
		xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
		xmlns:conv="clr-namespace:ShareDeployed.Mailgrabber.Converters"
        Title="Mail garbber" Height="350" Width="525" DataContext="{Binding Source={StaticResource Locator}, Path=Main}">
	<Window.Resources>
		<conv:BoolToVisibility x:Key="BoolToVisibility"/>
		<conv:ReverseBoolToVisibility x:Key="ReverseBoolToVisibility"/>
	</Window.Resources>
	<i:Interaction.Triggers>
		<i:EventTrigger EventName="Loaded">
			<cmd:EventToCommand Command="{Binding ProcessLoginCommand}"/>
		</i:EventTrigger>
		<i:EventTrigger EventName="StateChanged">
			<cmd:EventToCommand Command="{Binding StateChangedCommand}"/>
		</i:EventTrigger>
		<i:EventTrigger EventName="IsVisibleChanged">
			<cmd:EventToCommand Command="{Binding IsVisibleChangedCommand}"/>
		</i:EventTrigger>
		<i:EventTrigger EventName="Closing">
			<cmd:EventToCommand Command="{Binding ClosingCommand}"/>
		</i:EventTrigger>
	</i:Interaction.Triggers>
	<DockPanel>
		<Menu DockPanel.Dock="Top">
			<MenuItem Header="_File">
				<Separator/>
				<MenuItem Header="E_xit" Command="{Binding ExitCommand}"/>
			</MenuItem>
			<MenuItem Header="_Groups" IsEnabled="{Binding Path=EnableGroupsMenu, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
				<MenuItem Header="C_reate" Command="{Binding CreateGroupCommand}"/>
				<Separator/>
				<MenuItem Header="M_anage" Command="{Binding ManageGroupsCommand}"/>
			</MenuItem>
		</Menu>
		<Grid IsEnabled="{Binding IsLogged, UpdateSourceTrigger=PropertyChanged}">
			<Grid.RowDefinitions>
				<RowDefinition/>
				<RowDefinition Height="25"/>
				<RowDefinition Height="100"/>
			</Grid.RowDefinitions>
			<TextBlock Visibility="{Binding IsLogged, Converter={StaticResource ReverseBoolToVisibility}}">You are not logged in</TextBlock>
			<StatusBar Grid.Row="1">
				<StatusBarItem Content="{Binding LoginData.LoginName}"
							   Visibility="{Binding IsLogged,Converter={StaticResource BoolToVisibility}}"></StatusBarItem>
				<Separator></Separator>
				<StatusBarItem Content="{Binding UserGroups.Count, UpdateSourceTrigger=PropertyChanged,StringFormat='{}Groups count: {0}'}"
							   Visibility="{Binding IsLogged,Converter={StaticResource BoolToVisibility}}"></StatusBarItem>
				<Separator></Separator>
				<StatusBarItem Content="{Binding GroupToSend.Name, UpdateSourceTrigger=PropertyChanged, StringFormat='{}Default group: {0}'}"
							   Visibility="{Binding IsLogged,Converter={StaticResource BoolToVisibility}}"></StatusBarItem>
				<Separator></Separator>
				<StatusBarItem Content="{Binding LastObserved, UpdateSourceTrigger=PropertyChanged, StringFormat='{}Last observed: {0}'}"
							   Visibility="{Binding IsLogged,Converter={StaticResource BoolToVisibility}}"></StatusBarItem>
			</StatusBar>
			<ListBox ItemsSource="{Binding Path=NewMails,Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
				<ListBox.ItemTemplate>
					<DataTemplate>
						<StackPanel Orientation="Vertical">
							<TextBlock>
								<TextBlock.Text>
									<MultiBinding StringFormat="{}Subject: {0};  From: {1};  When:{2};">
										<Binding Path="Subject" />
										<Binding Path="From"/>
										
										<Binding Path="When" />
									</MultiBinding>
								</TextBlock.Text>
							</TextBlock>
						</StackPanel>
					</DataTemplate>
				</ListBox.ItemTemplate>
			</ListBox>
		</Grid>

	</DockPanel>
</Window>
